using ImageCSharp.Core.Models;
using SixLabors.ImageSharp;

namespace ImageCSharp.Core.Interfaces
{
    /// <summary>
    /// 图像服务接口
    /// </summary>
    public interface IImageService
    {
        /// <summary>
        /// 保存图像
        /// </summary>
        void SaveImage(ImageDocument document, string filePath);

        /// <summary>
        /// 加载图像
        /// </summary>
        ImageDocument LoadImage(string filePath);

        /// <summary>
        /// 调整图像大小
        /// </summary>
        void ResizeImage(ImageDocument document, int width, int height);

        /// <summary>
        /// 裁剪图像
        /// </summary>
        void CropImage(ImageDocument document, System.Drawing.Rectangle cropArea);

        /// <summary>
        /// 旋转图像
        /// </summary>
        void RotateImage(ImageDocument document, float angle);

        /// <summary>
        /// 翻转图像
        /// </summary>
        void FlipImage(ImageDocument document, bool horizontal, bool vertical);

        /// <summary>
        /// 应用滤镜
        /// </summary>
        void ApplyFilter(ImageDocument document, IFilterPlugin filter);
        ImageDocument ApplyFilter2(ImageDocument document, IFilterPlugin filter);

        /// <summary>
        /// 获取图像统计信息
        /// </summary>
        ImageStatistics GetStatistics(ImageDocument document);
    }

    /// <summary>
    /// 图像统计信息
    /// </summary>
    public class ImageStatistics
    {
        public int Width { get; set; }
        public int Height { get; set; }
        public double MeanBrightness { get; set; }
        public double MeanRed { get; set; }
        public double MeanGreen { get; set; }
        public double MeanBlue { get; set; }
        public double Contrast { get; set; }
        public double StandardDeviation { get; set; }
        public double Entropy { get; set; }
        public Dictionary<string, double> ColorDistribution { get; set; } = new();
        
        // 额外统计信息
        public int TotalPixels => Width * Height;
        public double AspectRatio => Width > 0 ? (double)Height / Width : 0;
        public double Megapixels => TotalPixels / 1000000.0;
    }
}